<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="java.util.*" %>
<%@ page import="com.sms.project.*" %>
<%@ page import="net.sf.json.*"%>

<%--
	project/teacher/query-project.jsp
 --%>

<%	//清除内存
	response.setHeader("Pragma","No-cache"); 
	response.setHeader("Cache-Control","no-cache"); 
	response.setDateHeader("Expires", 0); 
%>

<%
	request.setCharacterEncoding("utf-8");
	String userno = (String)session.getAttribute("userno");
	String row = request.getParameter("row");
	int num = Integer.parseInt(row);
	
	String msg = "ok";
	boolean isSuccess = true;
	String progress = request.getParameter("progress");
	String condition = "";
	if(progress != null) {
		if(progress.trim().equals("already")) {
			condition = "finish";
		} else if(progress.trim().equals("unalready")){
			condition = "notfinish";
		} else {
			condition = "";
		}
	} else {
		condition = "";
	}
	
	List<Project> list = new ArrayList<Project>();
	list = Task.getTProject(userno, condition);

	Project p = null;
	if(list != null && list.size() >0) {
		p = list.get(num);
	} else {
		isSuccess = false;
	}
	
	String oriStatus = p.getStatus();
	String nowStatus = oriStatus;
	if(isSuccess) {
		if(oriStatus.equals("0")) {
			nowStatus = "1";
		} else if(oriStatus.equals("1")) {
			nowStatus = "0";
		} else {
			isSuccess = false;
		}
	}
	
	if(isSuccess) {
		if(!Task.changeProgress(p.getProID(), nowStatus)) {
			isSuccess = false;
		}
	}
	
	if(isSuccess) {
		msg = "ok";
	} else {
		msg = "error";
	}
	
	msg = msg.replace("/rn/g", "");//去掉产生的换行
	out.clear();//去除要输出的内容
	out.write(msg);
%>